<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  // 字符串中和正则表达式配合使用的方法

  // search match replace split()

  // search  返回符合规则的某个或某段字符 第一次出现的位置
  var str = "good good study , Day dAy up";
  var reg = /day/ig;
  var index = str.search(reg);
  console.log(index);

  // match   将匹配的内容(符合规则的某个或某段字符)放到数组中
  var str = "good good study , Day dAy up";
  var reg = /day/i;    // 默认匹配一个
  var reg = /day/ig;   // 默认匹配整个字符串
  var index = str.match(reg);
  console.log(index);

  // replace   用新的字符串替换原本的字符串(符合规则的某个或某段字符)
  var str = "good good study , Day dAy up";
  var reg = /day/i;    // 默认匹配一个
  var reg = /day/ig;   // 默认匹配整个字符串
  var index = str.replace(reg, "money");
  console.log(index);

  // split()  用特定的字符(符合规则的某个或某段字符)分割字符串
  var str = "good     good   study  , Day  dAy up";
  var reg = /\s+/;   // \s空白字符(空格)   +一个或多个
  var arr = str.split(reg);
  console.log(arr);



</script>

</html>